package tp.pr5.console;

import java.util.List;

import tp.pr5.Constants;
import tp.pr5.Direction;
import tp.pr5.NavigationObserver;
import tp.pr5.PlaceInfo;
import tp.pr5.RobotEngineObserver;
import tp.pr5.ShopObserver;
import tp.pr5.items.InventoryObserver;
import tp.pr5.items.Item;

public class Console implements RobotEngineObserver, NavigationObserver, InventoryObserver, ShopObserver
{
	/**
	 * 	The robot engine informs that the communication is over.
	 */
	public void communicationCompleted() 
	{
		System.out.println(Constants.MESSAGE_FIN_QUIT);
	}

	/**
	 * The robot engine informs that the help has been requested
	 * 
	 * @param help
	 */
	public void communicationHelp(String help)
	{
		System.out.println(help);
	} 
	
	/**
	 * The robot engine informs that the robot has shut down (because it has arrived at the spaceship or it has run out of fuel)
	 * 
	 * @param win
	 */
	public void engineOff(boolean win)
	{
		if(win)
		{
			System.out.println(Constants.MESSAGE_FIN_SPACESHIP);
		}
		else
		{
			System.out.println(Constants.MESSAGE_DIE);
		}
	} 
	
	/**
	 * 	Notifies that the robot heading has changed
	 * 
	 * @param newHeading
	 */
	public void headingChanged(Direction newHeading)
	{
		System.out.println(Constants.MESSAGE_HEADING.replace("{DIRECTION}", newHeading.toString()));
	} 
	
	/**
	 * 	Notifies that the navigation module has been initialized
	 * 
	 * @param initialPlace
	 * @param heading
	 */
	public void initNavigationModule(PlaceInfo initialPlace, Direction heading)
	{
		System.out.println(initialPlace.toString());
		this.headingChanged(heading);
	} 
	
	/**
	 * 	Notifies that the container has changed
	 * 
	 * @param inventory
	 */
	public void inventoryChange(List<Item> inventory)
	{
		//empty
	} 
	
	/**
	 * Notifies that the user requests a SCAN instruction over the inventory.
	 * 
	 * @param collectionDescription
	 */
	public void inventoryScanned(String collectionDescription)
	{
		System.out.println("WALL·E says: I am carrying the following items");
		System.out.println(collectionDescription);
	} 
	
	/**
	 * 	Notifies that an item is empty and it will be removed from the container.
	 * 
	 * @param itemName
	 */
	public void itemEmpty(String itemName)
	{
		System.out.println(Constants.MESSAGE_EMPTY.replace("{ID}", itemName));
	} 
	
	/**
	 * 	Notifies that the user wants to scan an item allocated in the inventory
	 * 
	 * @param description
	 */
	public void itemScanned(String description)
	{
		
		System.out.println(description);
	} 
	
	/**
	 * 	Notifies that the place where the robot stays has changed (because the robot picked or dropped an item)
	 * 
	 * @param placeDescription
	 */
	public void placeHasChanged(PlaceInfo placeDescription)
	{
		//empty
	} 
	
	/**
	 * 	Notifies that the user requested a RADAR instruction
	 * 
	 * @param placeDescription 
	 */
	public void placeScanned(PlaceInfo placeDescription)
	{
		//System.out.println(placeDescription.toString());
		System.out.println(placeDescription.getDescription());
	} 
	
	/**
	 * 	The robot engine informs that it has raised an error
	 * 
	 * @param msg
	 */
	public void raiseError(String msg)
	{
		System.out.println(msg);
	} 
	
	/**
	 * 	Notifies that the robot has arrived at a place
	 * 
	 * @param heading
	 * @param place
	 */
	public void robotArrivesAtPlace(Direction heading, PlaceInfo place)
	{
		System.out.println(Constants.MESSAGE_MOVING.replace("{ID}", heading.toString()));
		System.out.println(place.toString());
	} 
	
	/**
	 * 	The robot engine informs that the robot wants to say something
	 * 
	 * @param message
	 */
	public void robotSays(String message)
	{
		System.out.println(message);
	} 
	
	/**
	 * 	The robot engine informs that the fuel and/or the amount of recycled material has changed 
	 * 
	 * @param fuel
	 * @param recycledMaterial
	 */
	public void robotUpdate(int fuel, int recycledMaterial)
	{
		System.out.println(Constants.MESSAGE_ROBOT_POWER.replace("{ID}", Integer.toString(fuel)));
		System.out.println(Constants.MESSAGE_ROBOT_RECYCLED_MATERIAL.replace("{ID}", Integer.toString(recycledMaterial)));
	}

	@Override
	public void askForShop(String description)
	{
		
	} 

}
